using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Commerce.Common
{
	/// <summary>
	/// Strongly-typed collection for the Address class.
	/// </summary>
	[Serializable]
	public partial class AddressCollection : ActiveList<Address,AddressCollection> 
	{	   
		public AddressCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the CSK_Store_Address table.
	/// </summary>
	[Serializable]
	public partial class Address : ActiveRecord<Address>, IActiveRecord
	{
		#region .ctors and Default Settings
		
		public Address()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public Address(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

        
		public Address(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public Address(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor	
		public static Query CreateQuery() { return new Query(Schema); }

		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("CSK_Store_Address", TableType.Table, DataService.GetInstance("dashCommerce"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarAddressID = new TableSchema.TableColumn(schema);
				colvarAddressID.ColumnName = "addressID";
				colvarAddressID.DataType = DbType.Int32;
				colvarAddressID.MaxLength = 0;
				colvarAddressID.AutoIncrement = true;
				colvarAddressID.IsNullable = false;
				colvarAddressID.IsPrimaryKey = true;
				colvarAddressID.IsForeignKey = false;
				colvarAddressID.IsReadOnly = false;
				colvarAddressID.DefaultSetting = @"";
				colvarAddressID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAddressID);
				
				TableSchema.TableColumn colvarUserName = new TableSchema.TableColumn(schema);
				colvarUserName.ColumnName = "userName";
				colvarUserName.DataType = DbType.String;
				colvarUserName.MaxLength = 50;
				colvarUserName.AutoIncrement = false;
				colvarUserName.IsNullable = false;
				colvarUserName.IsPrimaryKey = false;
				colvarUserName.IsForeignKey = false;
				colvarUserName.IsReadOnly = false;
				colvarUserName.DefaultSetting = @"";
				colvarUserName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUserName);
				
				TableSchema.TableColumn colvarFirstName = new TableSchema.TableColumn(schema);
				colvarFirstName.ColumnName = "firstName";
				colvarFirstName.DataType = DbType.String;
				colvarFirstName.MaxLength = 50;
				colvarFirstName.AutoIncrement = false;
				colvarFirstName.IsNullable = false;
				colvarFirstName.IsPrimaryKey = false;
				colvarFirstName.IsForeignKey = false;
				colvarFirstName.IsReadOnly = false;
				colvarFirstName.DefaultSetting = @"";
				colvarFirstName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarFirstName);
				
				TableSchema.TableColumn colvarLastName = new TableSchema.TableColumn(schema);
				colvarLastName.ColumnName = "lastName";
				colvarLastName.DataType = DbType.String;
				colvarLastName.MaxLength = 50;
				colvarLastName.AutoIncrement = false;
				colvarLastName.IsNullable = false;
				colvarLastName.IsPrimaryKey = false;
				colvarLastName.IsForeignKey = false;
				colvarLastName.IsReadOnly = false;
				colvarLastName.DefaultSetting = @"";
				colvarLastName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarLastName);
				
				TableSchema.TableColumn colvarPhone = new TableSchema.TableColumn(schema);
				colvarPhone.ColumnName = "phone";
				colvarPhone.DataType = DbType.String;
				colvarPhone.MaxLength = 50;
				colvarPhone.AutoIncrement = false;
				colvarPhone.IsNullable = true;
				colvarPhone.IsPrimaryKey = false;
				colvarPhone.IsForeignKey = false;
				colvarPhone.IsReadOnly = false;
				colvarPhone.DefaultSetting = @"";
				colvarPhone.ForeignKeyTableName = "";
				schema.Columns.Add(colvarPhone);
				
				TableSchema.TableColumn colvarEmail = new TableSchema.TableColumn(schema);
				colvarEmail.ColumnName = "email";
				colvarEmail.DataType = DbType.String;
				colvarEmail.MaxLength = 50;
				colvarEmail.AutoIncrement = false;
				colvarEmail.IsNullable = true;
				colvarEmail.IsPrimaryKey = false;
				colvarEmail.IsForeignKey = false;
				colvarEmail.IsReadOnly = false;
				colvarEmail.DefaultSetting = @"";
				colvarEmail.ForeignKeyTableName = "";
				schema.Columns.Add(colvarEmail);
				
				TableSchema.TableColumn colvarAddress1 = new TableSchema.TableColumn(schema);
				colvarAddress1.ColumnName = "address1";
				colvarAddress1.DataType = DbType.String;
				colvarAddress1.MaxLength = 50;
				colvarAddress1.AutoIncrement = false;
				colvarAddress1.IsNullable = false;
				colvarAddress1.IsPrimaryKey = false;
				colvarAddress1.IsForeignKey = false;
				colvarAddress1.IsReadOnly = false;
				colvarAddress1.DefaultSetting = @"";
				colvarAddress1.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAddress1);
				
				TableSchema.TableColumn colvarAddress2 = new TableSchema.TableColumn(schema);
				colvarAddress2.ColumnName = "address2";
				colvarAddress2.DataType = DbType.String;
				colvarAddress2.MaxLength = 50;
				colvarAddress2.AutoIncrement = false;
				colvarAddress2.IsNullable = true;
				colvarAddress2.IsPrimaryKey = false;
				colvarAddress2.IsForeignKey = false;
				colvarAddress2.IsReadOnly = false;
				colvarAddress2.DefaultSetting = @"";
				colvarAddress2.ForeignKeyTableName = "";
				schema.Columns.Add(colvarAddress2);
				
				TableSchema.TableColumn colvarCity = new TableSchema.TableColumn(schema);
				colvarCity.ColumnName = "city";
				colvarCity.DataType = DbType.String;
				colvarCity.MaxLength = 50;
				colvarCity.AutoIncrement = false;
				colvarCity.IsNullable = false;
				colvarCity.IsPrimaryKey = false;
				colvarCity.IsForeignKey = false;
				colvarCity.IsReadOnly = false;
				colvarCity.DefaultSetting = @"";
				colvarCity.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCity);
				
				TableSchema.TableColumn colvarStateOrRegion = new TableSchema.TableColumn(schema);
				colvarStateOrRegion.ColumnName = "stateOrRegion";
				colvarStateOrRegion.DataType = DbType.String;
				colvarStateOrRegion.MaxLength = 50;
				colvarStateOrRegion.AutoIncrement = false;
				colvarStateOrRegion.IsNullable = false;
				colvarStateOrRegion.IsPrimaryKey = false;
				colvarStateOrRegion.IsForeignKey = false;
				colvarStateOrRegion.IsReadOnly = false;
				colvarStateOrRegion.DefaultSetting = @"";
				colvarStateOrRegion.ForeignKeyTableName = "";
				schema.Columns.Add(colvarStateOrRegion);
				
				TableSchema.TableColumn colvarZip = new TableSchema.TableColumn(schema);
				colvarZip.ColumnName = "zip";
				colvarZip.DataType = DbType.String;
				colvarZip.MaxLength = 50;
				colvarZip.AutoIncrement = false;
				colvarZip.IsNullable = false;
				colvarZip.IsPrimaryKey = false;
				colvarZip.IsForeignKey = false;
				colvarZip.IsReadOnly = false;
				colvarZip.DefaultSetting = @"";
				colvarZip.ForeignKeyTableName = "";
				schema.Columns.Add(colvarZip);
				
				TableSchema.TableColumn colvarCountry = new TableSchema.TableColumn(schema);
				colvarCountry.ColumnName = "country";
				colvarCountry.DataType = DbType.String;
				colvarCountry.MaxLength = 50;
				colvarCountry.AutoIncrement = false;
				colvarCountry.IsNullable = true;
				colvarCountry.IsPrimaryKey = false;
				colvarCountry.IsForeignKey = false;
				colvarCountry.IsReadOnly = false;
				colvarCountry.DefaultSetting = @"";
				colvarCountry.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCountry);
				
				TableSchema.TableColumn colvarCreatedOn = new TableSchema.TableColumn(schema);
				colvarCreatedOn.ColumnName = "createdOn";
				colvarCreatedOn.DataType = DbType.DateTime;
				colvarCreatedOn.MaxLength = 0;
				colvarCreatedOn.AutoIncrement = false;
				colvarCreatedOn.IsNullable = true;
				colvarCreatedOn.IsPrimaryKey = false;
				colvarCreatedOn.IsForeignKey = false;
				colvarCreatedOn.IsReadOnly = false;
				
						colvarCreatedOn.DefaultSetting = @"(getdate())";
				colvarCreatedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedOn);
				
				TableSchema.TableColumn colvarCreatedBy = new TableSchema.TableColumn(schema);
				colvarCreatedBy.ColumnName = "createdBy";
				colvarCreatedBy.DataType = DbType.String;
				colvarCreatedBy.MaxLength = 50;
				colvarCreatedBy.AutoIncrement = false;
				colvarCreatedBy.IsNullable = true;
				colvarCreatedBy.IsPrimaryKey = false;
				colvarCreatedBy.IsForeignKey = false;
				colvarCreatedBy.IsReadOnly = false;
				colvarCreatedBy.DefaultSetting = @"";
				colvarCreatedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCreatedBy);
				
				TableSchema.TableColumn colvarModifiedOn = new TableSchema.TableColumn(schema);
				colvarModifiedOn.ColumnName = "modifiedOn";
				colvarModifiedOn.DataType = DbType.DateTime;
				colvarModifiedOn.MaxLength = 0;
				colvarModifiedOn.AutoIncrement = false;
				colvarModifiedOn.IsNullable = true;
				colvarModifiedOn.IsPrimaryKey = false;
				colvarModifiedOn.IsForeignKey = false;
				colvarModifiedOn.IsReadOnly = false;
				
						colvarModifiedOn.DefaultSetting = @"(getdate())";
				colvarModifiedOn.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedOn);
				
				TableSchema.TableColumn colvarModifiedBy = new TableSchema.TableColumn(schema);
				colvarModifiedBy.ColumnName = "modifiedBy";
				colvarModifiedBy.DataType = DbType.String;
				colvarModifiedBy.MaxLength = 50;
				colvarModifiedBy.AutoIncrement = false;
				colvarModifiedBy.IsNullable = true;
				colvarModifiedBy.IsPrimaryKey = false;
				colvarModifiedBy.IsForeignKey = false;
				colvarModifiedBy.IsReadOnly = false;
				colvarModifiedBy.DefaultSetting = @"";
				colvarModifiedBy.ForeignKeyTableName = "";
				schema.Columns.Add(colvarModifiedBy);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["dashCommerce"].AddSchema("CSK_Store_Address",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("AddressID")]
		public int AddressID 
		{
			get { return GetColumnValue<int>(Columns.AddressID); }

			set { SetColumnValue(Columns.AddressID, value); }

		}

		  
		[XmlAttribute("UserName")]
		public string UserName 
		{
			get { return GetColumnValue<string>(Columns.UserName); }

			set { SetColumnValue(Columns.UserName, value); }

		}

		  
		[XmlAttribute("FirstName")]
		public string FirstName 
		{
			get { return GetColumnValue<string>(Columns.FirstName); }

			set { SetColumnValue(Columns.FirstName, value); }

		}

		  
		[XmlAttribute("LastName")]
		public string LastName 
		{
			get { return GetColumnValue<string>(Columns.LastName); }

			set { SetColumnValue(Columns.LastName, value); }

		}

		  
		[XmlAttribute("Phone")]
		public string Phone 
		{
			get { return GetColumnValue<string>(Columns.Phone); }

			set { SetColumnValue(Columns.Phone, value); }

		}

		  
		[XmlAttribute("Email")]
		public string Email 
		{
			get { return GetColumnValue<string>(Columns.Email); }

			set { SetColumnValue(Columns.Email, value); }

		}

		  
		[XmlAttribute("Address1")]
		public string Address1 
		{
			get { return GetColumnValue<string>(Columns.Address1); }

			set { SetColumnValue(Columns.Address1, value); }

		}

		  
		[XmlAttribute("Address2")]
		public string Address2 
		{
			get { return GetColumnValue<string>(Columns.Address2); }

			set { SetColumnValue(Columns.Address2, value); }

		}

		  
		[XmlAttribute("City")]
		public string City 
		{
			get { return GetColumnValue<string>(Columns.City); }

			set { SetColumnValue(Columns.City, value); }

		}

		  
		[XmlAttribute("StateOrRegion")]
		public string StateOrRegion 
		{
			get { return GetColumnValue<string>(Columns.StateOrRegion); }

			set { SetColumnValue(Columns.StateOrRegion, value); }

		}

		  
		[XmlAttribute("Zip")]
		public string Zip 
		{
			get { return GetColumnValue<string>(Columns.Zip); }

			set { SetColumnValue(Columns.Zip, value); }

		}

		  
		[XmlAttribute("Country")]
		public string Country 
		{
			get { return GetColumnValue<string>(Columns.Country); }

			set { SetColumnValue(Columns.Country, value); }

		}

		
		
		//private DateTime? propCreatedOn;
		[XmlAttribute("CreatedOn")]
		public DateTime CreatedOn 
		{
			get
			{
			DateTime? propCreatedOn = GetColumnValue<DateTime?>(Columns.CreatedOn);
				if (!propCreatedOn.HasValue)
					return new DateTime(1900,01, 01);
				return propCreatedOn.Value;
			}

		   set { SetColumnValue(Columns.CreatedOn, value); }

		}

		
		[XmlIgnore]
		public bool CreatedOnHasValue
		{
			get { return GetColumnValue<DateTime?>("createdOn") != null; }

			set
			{
				DateTime? propCreatedOn = GetColumnValue<DateTime?>(Columns.CreatedOn);
				if (!value)
					SetColumnValue(Columns.CreatedOn, null);
				else if (value && !propCreatedOn.HasValue)
					SetColumnValue(Columns.CreatedOn, new DateTime(1900,01, 01));
		   }

		}

		
		  
		[XmlAttribute("CreatedBy")]
		public string CreatedBy 
		{
			get { return GetColumnValue<string>(Columns.CreatedBy); }

			set { SetColumnValue(Columns.CreatedBy, value); }

		}

		
		
		//private DateTime? propModifiedOn;
		[XmlAttribute("ModifiedOn")]
		public DateTime ModifiedOn 
		{
			get
			{
			DateTime? propModifiedOn = GetColumnValue<DateTime?>(Columns.ModifiedOn);
				if (!propModifiedOn.HasValue)
					return new DateTime(1900,01, 01);
				return propModifiedOn.Value;
			}

		   set { SetColumnValue(Columns.ModifiedOn, value); }

		}

		
		[XmlIgnore]
		public bool ModifiedOnHasValue
		{
			get { return GetColumnValue<DateTime?>("modifiedOn") != null; }

			set
			{
				DateTime? propModifiedOn = GetColumnValue<DateTime?>(Columns.ModifiedOn);
				if (!value)
					SetColumnValue(Columns.ModifiedOn, null);
				else if (value && !propModifiedOn.HasValue)
					SetColumnValue(Columns.ModifiedOn, new DateTime(1900,01, 01));
		   }

		}

		
		  
		[XmlAttribute("ModifiedBy")]
		public string ModifiedBy 
		{
			get { return GetColumnValue<string>(Columns.ModifiedBy); }

			set { SetColumnValue(Columns.ModifiedBy, value); }

		}

		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
        
        
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(string varUserName,string varFirstName,string varLastName,string varPhone,string varEmail,string varAddress1,string varAddress2,string varCity,string varStateOrRegion,string varZip,string varCountry,DateTime varCreatedOn,string varCreatedBy,DateTime varModifiedOn,string varModifiedBy)
		{
			Address item = new Address();
			
			item.UserName = varUserName;
			
			item.FirstName = varFirstName;
			
			item.LastName = varLastName;
			
			item.Phone = varPhone;
			
			item.Email = varEmail;
			
			item.Address1 = varAddress1;
			
			item.Address2 = varAddress2;
			
			item.City = varCity;
			
			item.StateOrRegion = varStateOrRegion;
			
			item.Zip = varZip;
			
			item.Country = varCountry;
			
			item.CreatedOn = varCreatedOn;
			
			item.CreatedBy = varCreatedBy;
			
			item.ModifiedOn = varModifiedOn;
			
			item.ModifiedBy = varModifiedBy;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varAddressID,string varUserName,string varFirstName,string varLastName,string varPhone,string varEmail,string varAddress1,string varAddress2,string varCity,string varStateOrRegion,string varZip,string varCountry,DateTime varCreatedOn,string varCreatedBy,DateTime varModifiedOn,string varModifiedBy)
		{
			Address item = new Address();
			
				item.AddressID = varAddressID;
			
				item.UserName = varUserName;
			
				item.FirstName = varFirstName;
			
				item.LastName = varLastName;
			
				item.Phone = varPhone;
			
				item.Email = varEmail;
			
				item.Address1 = varAddress1;
			
				item.Address2 = varAddress2;
			
				item.City = varCity;
			
				item.StateOrRegion = varStateOrRegion;
			
				item.Zip = varZip;
			
				item.Country = varCountry;
			
				item.CreatedOn = varCreatedOn;
			
				item.CreatedBy = varCreatedBy;
			
				item.ModifiedOn = varModifiedOn;
			
				item.ModifiedBy = varModifiedBy;
			
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
        
        
        
        #region Typed Columns
        
        
        public static TableSchema.TableColumn AddressIDColumn
        {
            get { return Schema.Columns[0]; }

        }

        
        
        
        public static TableSchema.TableColumn UserNameColumn
        {
            get { return Schema.Columns[1]; }

        }

        
        
        
        public static TableSchema.TableColumn FirstNameColumn
        {
            get { return Schema.Columns[2]; }

        }

        
        
        
        public static TableSchema.TableColumn LastNameColumn
        {
            get { return Schema.Columns[3]; }

        }

        
        
        
        public static TableSchema.TableColumn PhoneColumn
        {
            get { return Schema.Columns[4]; }

        }

        
        
        
        public static TableSchema.TableColumn EmailColumn
        {
            get { return Schema.Columns[5]; }

        }

        
        
        
        public static TableSchema.TableColumn Address1Column
        {
            get { return Schema.Columns[6]; }

        }

        
        
        
        public static TableSchema.TableColumn Address2Column
        {
            get { return Schema.Columns[7]; }

        }

        
        
        
        public static TableSchema.TableColumn CityColumn
        {
            get { return Schema.Columns[8]; }

        }

        
        
        
        public static TableSchema.TableColumn StateOrRegionColumn
        {
            get { return Schema.Columns[9]; }

        }

        
        
        
        public static TableSchema.TableColumn ZipColumn
        {
            get { return Schema.Columns[10]; }

        }

        
        
        
        public static TableSchema.TableColumn CountryColumn
        {
            get { return Schema.Columns[11]; }

        }

        
        
        
        public static TableSchema.TableColumn CreatedOnColumn
        {
            get { return Schema.Columns[12]; }

        }

        
        
        
        public static TableSchema.TableColumn CreatedByColumn
        {
            get { return Schema.Columns[13]; }

        }

        
        
        
        public static TableSchema.TableColumn ModifiedOnColumn
        {
            get { return Schema.Columns[14]; }

        }

        
        
        
        public static TableSchema.TableColumn ModifiedByColumn
        {
            get { return Schema.Columns[15]; }

        }

        
        
        
        #endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string AddressID = @"addressID";
			 public static string UserName = @"userName";
			 public static string FirstName = @"firstName";
			 public static string LastName = @"lastName";
			 public static string Phone = @"phone";
			 public static string Email = @"email";
			 public static string Address1 = @"address1";
			 public static string Address2 = @"address2";
			 public static string City = @"city";
			 public static string StateOrRegion = @"stateOrRegion";
			 public static string Zip = @"zip";
			 public static string Country = @"country";
			 public static string CreatedOn = @"createdOn";
			 public static string CreatedBy = @"createdBy";
			 public static string ModifiedOn = @"modifiedOn";
			 public static string ModifiedBy = @"modifiedBy";
						
		}

		#endregion
		
		
		
	}

}

